#include <iostream>
#include <queue>
using namespace std;
#define N 100001
struct Edge {
	int to;
	int nxt;
} e[N];

int n, e_cnt, m, heads[N];
int in[N], cnt;
bool ifans;
queue< int > q;
inline void add(int u, int v) {
	e[++e_cnt].to = v;
	e[e_cnt].nxt = heads[u];
	heads[u] = e_cnt;
}
int main() {
	// freopen("testdata.in", "r", stdin);
	// freopen("testdata.out", "w", stdout);
	cin >> n;
	cin >> m;
	int a, b;
	for (int i = 1; i <= m; ++i) {
		cin >> a >> b;
		add(a, b);
		in[b]++;
	}
	for (int i = 1; i <= n; ++i) {
		if (!in[i]) {
			q.push(i);
			++cnt;
		}
	}
	if (cnt > 1)
		ifans = true;
	cnt = 0;
	while (!q.empty()) {
		int t = q.front();
		q.pop();
		cout << t << endl;
		cnt = 0;
		for (int i = heads[t]; i; i = e[i].nxt) {
			in[e[i].to]--;
			if (!in[e[i].to]) {
				q.push(e[i].to);
				++cnt;
			}
		}
		if (cnt > 1)
			ifans = true;
	}
	cout << (ifans ? 1 : 0);
	// fclose(stdin);
	// fclose(stdout);
	return 0;
}